package com.qf.business.redenvlopes.controller;

import com.qf.business.redenvlopes.service.RedEnvlopesService;
import com.qf.commons.base.result.R;
import com.qf.commons.base.result.Rs;
import com.qf.commons.web.aspect.annotation.GetUser;
import com.qf.commons.web.aspect.utils.UserUtils;
import com.qf.data.redenvlopes.vo.RedSendVo;
import com.qf.data.user.entity.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author Ken
 * create_time 2022/12/3
 */
@RestController
@RequestMapping("/red")
@Slf4j
public class RedController {

    @Autowired
    private RedEnvlopesService redEnvlopesService;

    /**
     * 发送红包
     * @return
     */
    @RequestMapping("/send")
    @GetUser
    public R send(RedSendVo redSendVo){
        log.debug("[send red] 发送红包 - {}", redSendVo);
        Student student = UserUtils.getUser(Student.class);
        redSendVo.setSid(student.getId());
        //返回红包id
        long redid = redEnvlopesService.sendRed(redSendVo);
        return Rs.create(redid);
    }

    /**
     * 抢红包
     * @return
     */
    @RequestMapping("/robred")
    public R robRed(Long redid){
        log.debug("[rob red] 抢红包的请求 - {}", redid);
        long score = redEnvlopesService.robRed(redid);
        return Rs.create(score);
    }
}
